package com.kaifamiao.www.demo.do0822;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Poker {

    //花色
    private final List<String> colors = List.of("♠","♥","♣","♦");

    //牌面
    private final List<String> nums = List.of("A","2","3","4","5","6","7","8","9","10","J","Q","k");

    //大小王
    private final List<String> jokers = List.of("joker","queen");

    //整副牌pokers
    private final List<String> pokers = new ArrayList<>();

    private void init(){
        for (String color:colors){
            for (String num : nums){
                pokers.add(color + num);
            }
        }
        pokers.addAll(jokers);
    }
    public Poker(){
        init();
    }
    public List<String> getPokers(){
        return pokers;
    }
    //洗牌
    public void shuffle(){
        Collections.shuffle(pokers);
    }
    @Override
    public String toString(){
        return pokers.toString();
    }
}
  class PokerComparator implements Comparator<String> {
    private final List<String> order = List.of("queen","joker","2","A","K","Q","J","10","9","8","7","6","5","4","3");
      @Override
      public int compare(String o1, String o2) {
          int index1 = order.indexOf(o1);
          int index2 = order.indexOf(o2);

          if (index1 < 0){
              index1 = order.indexOf(o1.substring(1));
          }
          if (index2 < 0){
              index2 = order.indexOf(o2.substring(1));
          }
          return index1 - index2;
      }
  }